
public class PlayerParser {
	Player parsedPlayer = new Player();
	String source;
	
	public PlayerParser(String s){
		source = s;
	}
	
	public Player parse(){
		getName();
		getClub();
		getClubLink();
		getAge();
		getNationality();
		getNominal();
		getPosition();
		getLiderstvo();
		getUdary();
		getVidenie();
		getNavesy();
		try{
			getReactia();
		} catch (Exception e) {
			// Do nothing
		}
		try{
			getPersonalka();
		} catch (Exception e) {
			// Do nothing
		}
		getShtrafnye();
		try{
			getUglovye();
		} catch (Exception e) {
			// Do nothing
		}
		try{
			getRuki();
		} catch (Exception e) {
			// Do nothing
		}
		getMoshi();
		getRabota();
		getDribling();
		getPas();
		try{
			getGolova();
		} catch (Exception e) {
			// Do nothing
		}
		try{
			getVyhody();
		} catch (Exception e) {
			// Do nothing
		}
		getDalinie();
		getSkorosti();
		getVybor();
		getTehnica();
		getOtbor();
		getVynos();
		
		return parsedPlayer;
	}
	
	private void getName(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = source.indexOf("<b>", index)+3;
		int index1 = source.indexOf(" (",index);
		parsedPlayer.setName(source.substring(index, index1));
	}
	private void getClub(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = source.indexOf(" (",index);
		index = source.indexOf(">",index)+1;
		int index1 = source.indexOf("</a>",index);
		parsedPlayer.setClub(source.substring(index, index1));
	}
	private void getClubLink(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = source.indexOf(" (",index);
		index = source.indexOf("<a href=\"",index)+9;
		int index1 = source.indexOf("\">",index);
		parsedPlayer.setClubLink(source.substring(index, index1));
	}
	private void getAge(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = source.indexOf(" (",index);
		index =  source.indexOf("<br>",index)+4;
		int index1 = source.indexOf(" ",index);
		parsedPlayer.setAge(Integer.parseInt(source.substring(index, index1)));
	}
	private void getNationality(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = source.indexOf(" (",index);
		index =  source.indexOf("<br>",index)+4;
		index =  source.indexOf(", ",index)+2;
		int index1 = source.indexOf(" (",index);
		parsedPlayer.setNationality(source.substring(index, index1));
	}	
	private void getNominal(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Номинал: ");
//		index = source.indexOf("Номинал: ",index)+6;
		int index1 = source.indexOf("$",index);
		parsedPlayer.setNominal(Integer.parseInt(source.substring(index, index1).replaceAll(",", "")));
	}
	private void getLiderstvo(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Лидерство");
//		index = source.indexOf("Лидерство",index);
		index = source.indexOf("</script>",index)+9;
		int index1 = source.indexOf(" ",index);
		int index2 = source.indexOf("<",index);
		index1 = index1<index2?index1:index2;
		parsedPlayer.setLiderstvo(Integer.parseInt(source.substring(index, index1)));
	}
	private void getPosition(){
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Номинал: ");
//		index = source.indexOf("Номинал: ",index);
		index = source.indexOf("<br>",index)+4;
		int index1 = source.indexOf("</b>",index);
		parsedPlayer.setPosition(source.substring(index, index1));
	}
	public void getUdary() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Удары");
//		index = source.indexOf("Удары",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setUdary(Integer.parseInt(source.substring(index, index1)));
	}

	public void getVidenie() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Видение поля");
//		index = source.indexOf("Видение",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setVidenie(Integer.parseInt(source.substring(index, index1)));
	}
	public void getNavesy() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Навесы");
//		index = source.indexOf("Навесы",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setNavesy(Integer.parseInt(source.substring(index, index1)));
	}
	public void getReactia() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Реакция");
//		index = source.indexOf("Реакция",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setReactia(Integer.parseInt(source.substring(index, index1)));
	}
	public void getPersonalka() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Перс. опека");
//		index = source.indexOf("Перс. опека",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setPersonalka(Integer.parseInt(source.substring(index, index1)));
	}
	public void getShtrafnye() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Штрафные");
//		index = source.indexOf("Штрафные",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setShtrafnye(Integer.parseInt(source.substring(index, index1)));
	}
	public void getUglovye() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Угловые");
//		index = source.indexOf("Угловые",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setUglovye(Integer.parseInt(source.substring(index, index1)));
	}
	public void getRuki() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Игра руками");
//		index = source.indexOf("Игра руками",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setRuki(Integer.parseInt(source.substring(index, index1)));
	}
	public void getRabota() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Работоспособность");
//		index = source.indexOf("Работоспособность",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setRabota(Integer.parseInt(source.substring(index, index1)));
	}
	public void getMoshi() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Мощь");
//		index = source.indexOf("Мощь",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setMoshi(Integer.parseInt(source.substring(index, index1)));
	}
	public void getDribling() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Дриблинг");
//		index = source.indexOf("Дриблинг",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setDribling(Integer.parseInt(source.substring(index, index1)));
	}
	public void getPas() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Игра в пас");
//		index = source.indexOf("Игра в пас",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setPas(Integer.parseInt(source.substring(index, index1)));
	}
	public void getGolova() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Игра головой");
//		index = source.indexOf("Игра головой",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setGolova(Integer.parseInt(source.substring(index, index1)));
	}
	public void getVyhody() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Игра на выходах");
//		index = source.indexOf("Игра на выходах",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setVyhody(Integer.parseInt(source.substring(index, index1)));
	}
	public void getDalinie() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Дальние удары");
//		index = source.indexOf("Дальние удары",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setDalinie(Integer.parseInt(source.substring(index, index1)));
	}
	public void getSkorosti() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Скорость");
//		index = source.indexOf("Скорость",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setSkorosti(Integer.parseInt(source.substring(index, index1)));
	}
	public void getVybor() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Выбор позиции");
//		index = source.indexOf("Выбор позиции",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setVybor(Integer.parseInt(source.substring(index, index1)));
	}
	public void getTehnica() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Техника");
//		index = source.indexOf("Техника",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setTehnica(Integer.parseInt(source.substring(index, index1)));
	}
	public void getOtbor() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Отбор мяча");
//		index = source.indexOf("Отбор мяча",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setOtbor(Integer.parseInt(source.substring(index, index1)));
	}
	public void getVynos() {
		int index = source.indexOf("<td class=\"back1\"><span class=\"text2b\"></span></td>");
		index = lookUpTo(source, index, "Выносливость");
//		index = source.indexOf("Выносливость",index);
		index = getMaximalIndex(source, index, "</script>","cript><b>");
		index+=9;
		int index1 = getMinimalIndex(source,index," ","<","*");
		parsedPlayer.setVynos(Integer.parseInt(source.substring(index, index1)));
	}
	
	private int getMinimalIndex(String source,int startIndex,String...strings ){
		int minimum = 999999;
		for (String string:strings){
			int newIndex = source.indexOf(string,startIndex);
			if (newIndex>0&&newIndex<minimum){
				minimum=newIndex;
			}
		}
		return minimum;
	}
	
	private int getMaximalIndex(String source,int startIndex,String...strings ){
		int minimum = -1;
		for (String string:strings){
			int newIndex = source.indexOf(string,startIndex);
			if (newIndex>0&&newIndex>minimum){
				minimum=newIndex;
			}
		}
		return minimum;
	}
	private int lookUpTo(String source,int startIndex,String stringToLookUp){
		int index = startIndex;
		for (char ch:stringToLookUp.toCharArray()){
			index = source.indexOf(ch,index)+1;
		}
		
		return index; 
	}
}
